package com.jcodes.simple.module.auth.service;

import com.jcodes.simple.module.auth.controller.ro.UserUpdateRo;

import java.util.Objects;

import org.springframework.core.convert.ConversionService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jcodes.simple.module.auth.controller.ro.UserCreateRo;
import com.jcodes.simple.module.auth.entity.User;
import com.jcodes.simple.module.auth.mapper.UserMapper;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    private final ConversionService conversionService;

    public UserService(ConversionService conversionService) {
        this.conversionService = conversionService;
    }

    /**
     * 创建用户
     *
     * @param ro 请求对象
     * @return 结果
     */
    public Long create(UserCreateRo ro) {
        User user = this.conversionService.convert(ro, User.class);
        Objects.requireNonNull(user, "用户信息不能为空");
        this.save(user);
        return user.getId();
    }

    public Long update(UserUpdateRo ro) {
        User user = this.conversionService.convert(ro, User.class);
        Objects.requireNonNull(user, "用户信息不能为空");
        this.updateById(user);
        return user.getId();
    }

    public void delete(Long id) {
        this.removeById(id);
    }

//    public void findPage(){
//        this.findPage();
//    }
    // 增删改查
}
